
class_name CPubPlayerInfo

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal CharName_changed(old_value, new_value) 
signal CurClassID_changed(old_value, new_value) 
signal CurClassLevel_changed(old_value, new_value) 
signal Level_changed(old_value, new_value) 
signal CurHP_changed(old_value, new_value) 
signal MaxHP_changed(old_value, new_value) 
signal CurMP_changed(old_value, new_value) 
signal MaxMP_changed(old_value, new_value) 
signal CurSceneUUID_changed(old_value, new_value) 
signal PosX_changed(old_value, new_value) 
signal PosY_changed(old_value, new_value) 
signal LineID_changed(old_value, new_value) 
signal WeaponID_changed(old_value, new_value) 
signal NetStateStamp_changed(old_value, new_value) 
signal CurHeadPortrait_changed(old_value, new_value) 
signal CurHeadPortraitFrame_changed(old_value, new_value) 
signal ExploreTimes_changed(old_value, new_value) 
signal CombatEffectiveness_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.CharName = ''
    self.CurClassID = 0
    self.CurClassLevel = 0
    self.Level = 0
    self.CurHP = 0
    self.MaxHP = 0
    self.CurMP = 0
    self.MaxMP = 0
    self.CurSceneUUID = 0
    self.PosX = 0
    self.PosY = 0
    self.LineID = 0
    self.WeaponID = 0
    self.NetStateStamp = 0
    self.CurHeadPortrait = 0
    self.CurHeadPortraitFrame = 0
    self.ExploreTimes = 0
    self.CombatEffectiveness = 0	# 战斗力

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.CharName = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_CharName)
    self.CurClassID = _bufferStream.ReadUint8()
    self.CurClassLevel = _bufferStream.ReadUint8()
    self.Level = _bufferStream.ReadUint16()
    self.CurHP = _bufferStream.ReadUint32()
    self.MaxHP = _bufferStream.ReadUint32()
    self.CurMP = _bufferStream.ReadUint32()
    self.MaxMP = _bufferStream.ReadUint32()
    self.CurSceneUUID = _bufferStream.ReadInt64()
    self.PosX = _bufferStream.ReadInt32()
    self.PosY = _bufferStream.ReadInt32()
    self.LineID = _bufferStream.ReadInt32()
    self.WeaponID = _bufferStream.ReadInt32()
    self.NetStateStamp = _bufferStream.ReadUint32()
    self.CurHeadPortrait = _bufferStream.ReadUint8()
    self.CurHeadPortraitFrame = _bufferStream.ReadUint8()
    self.ExploreTimes = _bufferStream.ReadUint8()
    self.CombatEffectiveness = _bufferStream.ReadUint64()

    self.bInited = true


func GetTableName():
    return 'PubPlayerInfo'

func CopyFrom(other):
    self.CharName = other.CharName
    self.CurClassID = other.CurClassID
    self.CurClassLevel = other.CurClassLevel
    self.Level = other.Level
    self.CurHP = other.CurHP
    self.MaxHP = other.MaxHP
    self.CurMP = other.CurMP
    self.MaxMP = other.MaxMP
    self.CurSceneUUID = other.CurSceneUUID
    self.PosX = other.PosX
    self.PosY = other.PosY
    self.LineID = other.LineID
    self.WeaponID = other.WeaponID
    self.NetStateStamp = other.NetStateStamp
    self.CurHeadPortrait = other.CurHeadPortrait
    self.CurHeadPortraitFrame = other.CurHeadPortraitFrame
    self.ExploreTimes = other.ExploreTimes
    self.CombatEffectiveness = other.CombatEffectiveness


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CPubPlayerInfo.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CPubPlayerInfo", [self, old, self])
        return true

    print("UnPackField error tblName = PubPlayerInfo, className = CPubPlayerInfo, _fieldId = ", _fieldId)
    # if _fieldId > Fields_PubPlayerInfoID.size():
    #     var szLog = 'CPubPlayerInfo.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_PubPlayerInfoID(%d)' % [_fieldId, _fieldId,  Fields_PubPlayerInfoID.size()]
    #     print(szLog)
    #     return false

    # Fields_PubPlayerInfoID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CPubPlayerInfo", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CPubPlayerInfo", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var CharName:
    set(value):
        var old = self.m_CharName
        self.CharName = _value
        self.CharName_changed.emit(old, _value)

    get:
        return self.CharName


var CurClassID:
    set(value):
        var old = self.m_CurClassID
        self.CurClassID = _value
        self.CurClassID_changed.emit(old, _value)

    get:
        return self.CurClassID


var CurClassLevel:
    set(value):
        var old = self.m_CurClassLevel
        self.CurClassLevel = _value
        self.CurClassLevel_changed.emit(old, _value)

    get:
        return self.CurClassLevel


var Level:
    set(value):
        var old = self.m_Level
        self.Level = _value
        self.Level_changed.emit(old, _value)

    get:
        return self.Level


var CurHP:
    set(value):
        var old = self.m_CurHP
        self.CurHP = _value
        self.CurHP_changed.emit(old, _value)

    get:
        return self.CurHP


var MaxHP:
    set(value):
        var old = self.m_MaxHP
        self.MaxHP = _value
        self.MaxHP_changed.emit(old, _value)

    get:
        return self.MaxHP


var CurMP:
    set(value):
        var old = self.m_CurMP
        self.CurMP = _value
        self.CurMP_changed.emit(old, _value)

    get:
        return self.CurMP


var MaxMP:
    set(value):
        var old = self.m_MaxMP
        self.MaxMP = _value
        self.MaxMP_changed.emit(old, _value)

    get:
        return self.MaxMP


var CurSceneUUID:
    set(value):
        var old = self.m_CurSceneUUID
        self.CurSceneUUID = _value
        self.CurSceneUUID_changed.emit(old, _value)

    get:
        return self.CurSceneUUID


var PosX:
    set(value):
        var old = self.m_PosX
        self.PosX = _value
        self.PosX_changed.emit(old, _value)

    get:
        return self.PosX


var PosY:
    set(value):
        var old = self.m_PosY
        self.PosY = _value
        self.PosY_changed.emit(old, _value)

    get:
        return self.PosY


var LineID:
    set(value):
        var old = self.m_LineID
        self.LineID = _value
        self.LineID_changed.emit(old, _value)

    get:
        return self.LineID


var WeaponID:
    set(value):
        var old = self.m_WeaponID
        self.WeaponID = _value
        self.WeaponID_changed.emit(old, _value)

    get:
        return self.WeaponID


var NetStateStamp:
    set(value):
        var old = self.m_NetStateStamp
        self.NetStateStamp = _value
        self.NetStateStamp_changed.emit(old, _value)

    get:
        return self.NetStateStamp


var CurHeadPortrait:
    set(value):
        var old = self.m_CurHeadPortrait
        self.CurHeadPortrait = _value
        self.CurHeadPortrait_changed.emit(old, _value)

    get:
        return self.CurHeadPortrait


var CurHeadPortraitFrame:
    set(value):
        var old = self.m_CurHeadPortraitFrame
        self.CurHeadPortraitFrame = _value
        self.CurHeadPortraitFrame_changed.emit(old, _value)

    get:
        return self.CurHeadPortraitFrame


var ExploreTimes:
    set(value):
        var old = self.m_ExploreTimes
        self.ExploreTimes = _value
        self.ExploreTimes_changed.emit(old, _value)

    get:
        return self.ExploreTimes


var CombatEffectiveness:
    set(value):
        var old = self.m_CombatEffectiveness
        self.CombatEffectiveness = _value
        self.CombatEffectiveness_changed.emit(old, _value)

    get:
        return self.CombatEffectiveness



